#include "my_app.h"
#include "my_app_config.h"
#include "bsp_module.h"
#include "utils.h"
#include "my_errno.h"

SysRunData runData;


void systemDataRefresh(void)
{
	static uint8_t tLastKeyStatus;

	runData.tKeyStatus.isKey1Press = bsp_getKey1();
	runData.tKeyStatus.isKey2Press = bsp_getKey2();

	PSysRunData ptRunData = sys_getRunData();
	if (tLastKeyStatus != ptRunData->tKeyStatus.statu)         //if (tPreKeyStatus != runData.tKeyStatus.statu)
	{
		LOG_DEBUG("keystatus change, lastKeyStatus=0x%x, nowKeyStatus=0x%x\r\n", tLastKeyStatus, ptRunData->tKeyStatus.statu);
		tLastKeyStatus = ptRunData->tKeyStatus.statu;
		
	}
}


void taskInitEntry(void* arg)
{

	//bsp_moduleInit();
	if (ESUCCESS != bsp_moduleInit())
  	return;

  	static int timerCnt;

	//bsp_debugComWrite("Hello world", 11, 1000);
	LOG_DEBUG("taskInitEntry\r\n");
	printf("task Start\r\n");
	
	while (1)
	{
		systemDataRefresh();

		//printf("task Start\r\n");
		vTaskDelay(10);
	}
}



void my_app(void)
{
	xTaskCreate(taskInitEntry, "init_task", TASK_STK_SIZE_INIT_CTRL, NULL, TASK_PRIO_INIT_CTRL, NULL);
}

//------------------------------------------------
PSysRunData sys_getRunData(void)
{
	return &runData;
}


